package traceMyItems.business;

import java.util.*;
import java.util.logging.Logger;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.apache.commons.lang.NotImplementedException;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class Team {
	private static final Logger log = Logger.getLogger(Team.class.getName());
	
	
	
	@Persistent
	private String strName;

	@Persistent
	private List<User> lstUsers;
	
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key=null;
	
	
	public void createKey() {
        //this.key = KeyFactory.createKey(User.class.getSimpleName(), strUsername+":"+strEmail);
		///TODO: Aun queda crear criterio de creacion de clave para esta clase
		this.key = null;
    }
	
	public Key getKey()
	{
		return key;
	}
	
	
	public Team()
	{
		super();
		lstUsers = new ArrayList<User>();
	}

	public void addUser(User objUser) throws NotImplementedException
	{
		lstUsers.add(objUser);
	}
	
	public void removeUser(User objUser) throws NotImplementedException
	{
		lstUsers.remove(objUser);
	}
	
	public String getName() throws NotImplementedException
	{
		return strName;
	}
	
	public void setName(String strNameParam) throws NotImplementedException
	{
		strName = strNameParam;
	}
	
	public Boolean contieneUsuario (User usuario){
		for (User usr : this.lstUsers) {
			if (usr.getUsername() == usuario.getUsername())
				return true;
		}
		return false;
	}
}
